package org.csu.jpetstore.persistence;

import java.sql.*;

public class DBUtil {
    private static String DRIVER_CLASS = "com.mysql.jdbc.Driver";
    private static String URL = "jdbc:mysql://localhost:3306/jpetstore?useUnicode=true&autoReconnect=true&characterEncoding=UTF-8&useSSL=false";
    private static String USERNAME = "root";
    private static String PASSWORD = "123456";

    public static Connection getConnection() throws Exception{
        Class.forName(DRIVER_CLASS);
        Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        return connection;
    }

    public static void closeConnection(Connection connection) throws Exception{
        if(connection != null)
            connection.close();
    }

    public static void closeStatement(Statement statement) throws Exception{
        if(statement != null)
            statement.close();
    }

    public static void closePreparedStatement(PreparedStatement preparedStatement) throws Exception{
        if(preparedStatement != null)
            preparedStatement.close();
    }

    public static void closeResultSet(ResultSet resultSet) throws Exception{
        if(resultSet != null)
            resultSet.close();
    }

//    public static void main(String[] args) throws Exception {
//        Connection connection = DBUtil.getConnection();
//        System.out.println(connection);
//    }

}
